package com.lvfeng.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lvfeng.system.pojo.User;
import com.lvfeng.system.service.UserService;

/**
 * @author Administrator
 * 用户控制器
 */
@RestController	//全局控制
@RequestMapping("/user")	//请求域
public class UserController {
	@Autowired	//自动装载Service层
	UserService userService;

	private User user;
	@GetMapping
	public List<User> getAllUser(){
		List<User> lis = userService.getAllUser();	//从UserService里获取全部用户
		System.out.println("数据集合长度是："+lis.size());
		return lis;
	}

	/**
	 *   用户登录
	 * @param username
	 * @param password
	 * @return
	 */
	@PostMapping("/login")
	@ResponseBody
	public Map uLogin(@RequestParam("username") String username,@RequestParam("password") String password){
		// 1、 封装用户名、密码、是否记住我到token令牌对象  [支持记住我]
//		AuthenticationToken token = new UsernamePasswordToken(user.getUserName(),  DigestUtils.md5Hex(user.getPassword()),rememberMe);
		System.out.println(username + "" + password);
		String res = userService.login(username,password);
		Map m = new HashMap();
		if(res != null){
			m.put("state","success");
			return m;
		}else{
			m.put("state","error");
			return m;
		}
	}
	
	
}
